/**
 * 修改部门
 */
package ms.core.gateway.request;

import java.util.Map;

import com.alibaba.fastjson.annotation.JSONField;

import lombok.Data;
import ms.core.common.AppException;
import ms.core.common.consts.SysErr;
import ms.core.tool.JsonTool;
import ms.core.tool.StrTool;

@Data
public class UpdateDeptRequest {
	@JSONField(serialize=false)
	private Long id;				// 记录Id
	private String deptCode;		// 部门编码
	private String deptName;		// 部门名称
	private String leader;			// 负责人
	private String linkTel;			// 联系电话
	private String pUid;			// 父部门编码
	private int showIdx;			// 记录显示顺序
	
	public static UpdateDeptRequest getInstance(Map<String, Object> body) {
		UpdateDeptRequest dept = JsonTool.objectToBean(body, UpdateDeptRequest.class);
		if (dept==null)
			throw new AppException(SysErr.SYS_PARAM_ERR, "无效更新部门参数对象.");

		if (dept.getId()==null || dept.getId()<1)
			throw new AppException(SysErr.SYS_PARAM_ERR, "请选择更新部门.");
			
		if (StrTool.isBlank(dept.getDeptCode()) || StrTool.isBlank(dept.getDeptName()))
			throw new AppException(SysErr.SYS_PARAM_ERR, "部门编码和部门名称不可为空.");

		return dept;
	}
}
